package at.tugraz.akm.forume;

import java.util.ArrayList;

import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import at.tugraz.akm.forume.adapter.ThreadAdapter;
import at.tugraz.akm.forume.bean.Thread;
import at.tugraz.akm.forume.webservice.Client;

public class SearchableActivity extends ListActivity {

	ArrayList<Thread> threads;

	// @Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.searchs);

		threads = new ArrayList<Thread>();
		Intent intent = getIntent();
		if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
			String query = intent.getStringExtra(SearchManager.QUERY);
			threads = Client.search(getApplicationContext(), query);
		}
		
		ImageView search = (ImageView) findViewById(R.id.search);
		search.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onSearchRequested();
			}
		});

		ThreadAdapter ta = new ThreadAdapter(this, R.layout.thread_row, threads);
		setListAdapter(ta);
	}
}
